package com.springcloud.zuuldemo.config

import jdk.nashorn.internal.runtime.GlobalConstants
import org.springframework.boot.autoconfigure.security.oauth2.client.EnableOAuth2Sso
import org.springframework.cloud.client.loadbalancer.LoadBalanced
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import org.springframework.security.config.annotation.web.builders.HttpSecurity
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter
import org.springframework.security.oauth2.client.OAuth2ClientContext
import org.springframework.security.oauth2.client.OAuth2RestTemplate
import org.springframework.security.oauth2.client.resource.OAuth2ProtectedResourceDetails

@Configuration
@EnableOAuth2Sso

class OAuthClientConfig  {

    /*
        使用OAuth2RestTemple发出的请求会携带以Token为值的Authorization请求头
     */
    @Bean
    @LoadBalanced
    OAuth2RestTemplate oAuth2RestTemplate(OAuth2ProtectedResourceDetails resourceDetails,OAuth2ClientContext context)
    {
        new OAuth2RestTemplate(resourceDetails,context)
    }


}
